package cn.itcast.controller;

import cn.itcast.domain.Account;
import cn.itcast.service.AccountService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/*
* @PackageName:cn.itcast.controller
* 账户WEB
* @Class:AccountController
* @author:ledehui
* @Date:2020/11/2 16:39
*/
@Controller
@RequestMapping("/account")
public class AccountController {

   @Autowired
    private AccountService accountService;

    @RequestMapping("/findAll")
    public  String findAll(Model model){
        System.out.println("表现层：findAll......");
//        调用service的方法
        List<Account> list = accountService.findAll();
        model.addAttribute("list",list);
        return  "list";
    }

    /**
     *
     * @param account
     * @return
     */
    @RequestMapping("/saveAccount")
    public void saveAccount(Account account, HttpServletRequest request, HttpServletResponse response) throws  Exception{
        System.out.println("表现层：saveAccount......");
        accountService.saveAccount(account);
        response.sendRedirect(request.getContextPath()+"/account/findAll");
        return;
    }
}
